<?php
global $_W,$_GPC;
$settings = $this->module['config'];
$openid = trim($_GPC["openid"]);
$appid_type = intval($_GPC["appid_type"]);//1为外卖2为商超
if($appid_type == 1 || $appid_type == 2){
	$cateid = 82;
}else{
	$cateid = 83;
}
$user = pdo_get($this->modulename . "_user", array("openid" => trim($_GPC["openid"]), "uniacid" => $_W["uniacid"]));
$share = pdo_get($this->modulename . "_ad", array("cateid" => $cateid, "uniacid" => $_W["uniacid"]));
if(!$share){$share['title'] = $settings['sharetitle'];$share['thumb'] = tomedia($settings['sharethumb']);}
if($settings['system_type'] == 1){
	$unionid = $user['unionid'];
	$user = pdo_get($this->modulename . "_user_u", array("unionid" => $unionid, "system_id" => $settings['system_id']));
}
if(!$openid){
	exit(json_encode(array('code' => 0, 'status' => 0, 'msg' => '用户信息获取失败')));
}


$elmwm_act_id = trim($_GPC["elmwm_act_id"]);
$type = intval($_GPC["type"]);//1获取链接
if($settings['system_type'] == 1){
	if($appid_type == 1 || $appid_type == 2){
		$user = pdo_get($this->modulename . "_user_u", array("unionid" => $unionid, "system_id" => $settings['system_id']));
		//获取美团推广链接
		if($settings['meituan_api_type'] == 1){
			if($appid_type == 1){
				if(!intval($settings["meituan_waimai_h5_url"])){$settings['meituan_waimai_h5_url'] = 2;}
				if($settings['poster_type'] == 1 && $type == 1){
					$params = array('actId' => $settings['meituan_waimai_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'linkType' => 1,'sign' => 1);
					$meituansign = $this->genSign($params,$settings['meituanapikey']);
					$res = file_get_contents('https://runion.meituan.com/generateLink?actId='.$settings['meituan_waimai_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&linkType=1&sign='.$meituansign);
					if($settings['errorcodeid'] == 56){
						var_dump($res);
					}
				}else{
					$params = array('actId' => $settings['meituan_waimai_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'linkType' => 4,'sign' => 1);
					$meituansign = $this->genSign($params,$settings['meituanapikey']);
					$res = file_get_contents('https://runion.meituan.com/generateLink?actId='.$settings['meituan_waimai_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&linkType=4&sign='.$meituansign);
					if($settings['errorcodeid'] == 57){
						var_dump($res);
					}
				}
				$res = json_decode($res,true);
				if($res['status'] == 0){
					if($settings['poster_type'] == 1 && $type == 1){
						$params = array('actId' => $settings['meituan_waimai_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'sign' => 1);
						$meituansign = $this->genSign($params,$settings['meituanapikey']);
						$rescode = file_get_contents('https://runion.meituan.com/miniCode?actId='.$settings['meituan_waimai_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&sign='.$meituansign);
						if($settings['errorcodeid'] == 58){
							var_dump($rescode);
						}
						$rescode = json_decode($rescode,true);
						$mtwm_url = $res['data'];
						$mtwm_h5 = $settings['waimaitt_meituanwm_tuantext_c'].$res['data'];
						$mtwm_qrcode = str_replace(array("http","https"),"https",$rescode['data']);
					}else{
						$params = array('actId' => $settings['meituan_waimai_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'sign' => 1);
						$meituansign = $this->genSign($params,$settings['meituanapikey']);
						$rescode = file_get_contents('https://runion.meituan.com/miniCode?actId='.$settings['meituan_waimai_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&sign='.$meituansign);
						if($settings['errorcodeid'] == 58){
							var_dump($rescode);
						}
						$rescode = json_decode($rescode,true);
						$mtwm_url = $res['data'];
						$mtwm_h5 = $settings['waimaitt_meituanwm_tuantext_c'].$res['data'];
						$mtwm_qrcode = str_replace(array("http","https"),"https",$rescode['data']);
					}
				}
				$backdata = array('mtwm_url' =>$mtwm_url,'mtwm_h5' => $mtwm_h5,'mtwm_qrcode' => $mtwm_qrcode);
			}elseif($appid_type == 2){
				if(!intval($settings["meituan_sc_h5_url"])){$settings['meituan_sc_h5_url'] = 4;}
				if($settings['poster_type'] == 1 && $type == 1){
					$params = array('actId' => $settings['meituan_sc_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'linkType' => 1,'sign' => 1);
					$meituansign = $this->genSign($params,$settings['meituanapikey']);
					$res = file_get_contents('https://runion.meituan.com/generateLink?actId='.$settings['meituan_sc_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&linkType=1&sign='.$meituansign);
					if($settings['errorcodeid'] == 59){
						var_dump($res);
					}
				}else{
					$params = array('actId' => $settings['meituan_sc_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'linkType' => 4,'sign' => 1);
					$meituansign = $this->genSign($params,$settings['meituanapikey']);
					$res = file_get_contents('https://runion.meituan.com/generateLink?actId='.$settings['meituan_sc_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&linkType=4&sign='.$meituansign);
					if($settings['errorcodeid'] == 60){
						var_dump($res);
					}
				}
				$res = json_decode($res,true);
				if($res['status'] == 0){
					if($settings['poster_type'] == 1 && $type == 1){
						$params = array('actId' => $settings['meituan_sc_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'sign' => 1);
						$meituansign = $this->genSign($params,$settings['meituanapikey']);
						$rescode = file_get_contents('https://runion.meituan.com/miniCode?actId='.$settings['meituan_sc_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&sign='.$meituansign);
						if($settings['errorcodeid'] == 61){
							var_dump($rescode);
						}
						$rescode = json_decode($rescode,true);
						$mtsc_url = $res['data'];
						$mtsc_h5 = $settings['waimaitt_meituansc_tuantext_c'].$res['data'];
						$mtsc_qrcode = str_replace(array("http","https"),"https",$rescode['data']);
					}else{
						$params = array('actId' => $settings['meituan_sc_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'sign' => 1);
						$meituansign = $this->genSign($params,$settings['meituanapikey']);
						$rescode = file_get_contents('https://runion.meituan.com/miniCode?actId='.$settings['meituan_sc_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&sign='.$meituansign);
						if($settings['errorcodeid'] == 61){
							var_dump($rescode);
						}
						$rescode = json_decode($rescode,true);
						$mtsc_url = $res['data'];
						$mtsc_h5 = $settings['waimaitt_meituansc_tuantext_c'].$res['data'];
						$mtsc_qrcode = str_replace(array("http","https"),"https",$rescode['data']);
					}
				}
				$backdata = array('mtsc_url' => $mtsc_url,'mtsc_h5' => $mtsc_h5,'mtsc_qrcode' => $mtsc_qrcode);
			}
		}elseif($settings['meituan_api_type'] == 2){
			if($appid_type == 1){
				$meituan_data["activity"] = $settings['meituangroup_waimai_activity'];
			}elseif($appid_type == 2){
				$meituan_data["activity"] = $settings['meituangroup_sc_activity'];
			}
			$timestamp = time();
			$key = $settings['meituangroup_AppKey'];
			$meituan_data["utmSource"] = $settings['meituangroup_utmSource'];
			$meituan_data["utmMedium"] = $this->aesencrypt($user['uid'],$key);
			pdo_update($this->modulename . "_user", array("utmMedium" => $meituan_data["utmMedium"]), array("openid" => $openid, "uniacid" => $_W["uniacid"]));
			if($settings['system_type'] == 1){
				pdo_update($this->modulename . "_user_u", array("utmMedium" => $meituan_data["utmMedium"]), array("unionid" => $unionid, "system_id" => $settings['system_id']));
			}
			$meituan_data["promotionId"] = $settings['meituangroup_pid'];
			$meituan_data["pageLevel"] = 1;
			$requestId = $meituan_data["utmSource"] . $timestamp;
			$accessToken = $this->aesencrypt($requestId,$key);
			$url = "https://union.dianping.com/api/promotion/link?timestamp=" . $timestamp . "&requestId=" . $requestId . "&utmSource=" . $meituan_data["utmSource"] . "&version=2.0&accessToken=" . $accessToken;
			$res = $this->curlPost($url,$meituan_data);
			if($appid_type == 1){
				$backdata = array('mtwm_url' => $res['data']['miniProgramPath'],'mtwm_h5' => $res['data']['shortLink'],'mtwm_qrcode' => $res['data']['miniProgramQrCode'],'mtwm_apitype' => 2);
			}elseif($appid_type == 2){
				$backdata = array('mtsc_url' => $res['data']['miniProgramPath'],'mtsc_h5' => $res['data']['shortLink'],'mtsc_qrcode' => $res['data']['miniProgramQrCode'],'mtwm_apitype' => 2);
			}
		}elseif($settings['meituan_api_type'] == 4){
			if($appid_type == 1){
				$actid = 1;
			}elseif($appid_type == 2){
				$actid = 2;
			}
			
			$res = json_decode(file_get_contents('http://api.jutuike.com/union/act?relation_flag_name=waimaixia&apikey='.$settings['jutuikeapikey'].'&act_id='.$actid.'&sid='.$user['uid']),true);
			if ($res['code'] == 1) {
				if($appid_type == 1){
					$backdata = array('mtwm_url' => $res['data']['we_app_info']['page_path'],'mtwm_h5' => $res['data']['h5'],'mtwm_qrcode' => $res['data']['we_app_info']['miniCode'],'mtwm_apitype' => 4);
				}elseif($appid_type == 2){
					$backdata = array('mtsc_url' => $res['data']['we_app_info']['page_path'],'mtsc_h5' => $res['data']['h5'],'mtsc_qrcode' => $res['data']['we_app_info']['miniCode'],'mtwm_apitype' => 4);
				}
				
			} else {
				exit(json_encode($res));
			}
		}else{
			$postdata = http_build_query(array('apikey' => $settings['ddxapikey'],'sid' => $user['uid'],'generate_we_app' => true,'qrcode' => true));
			$options = array(
					'http' => array(
					'method' => 'POST',
					'header' => 'Content-type:application/x-www-form-urlencoded',
					'content' => $postdata,
					'timeout' => 1 * 60 // 超时时间（单位:s）
				  )
				);
			$cxContext = stream_context_create($options);
			if($appid_type == 1){
				//外卖
				$wm = file_get_contents("http://api.tbk.dingdanxia.com/waimai/meituan_privilege", false, $cxContext);
				if($settings['errorcodeid'] == 62){
					var_dump($wm);
				}
				$wm = json_decode($wm,true);
				if($wm['code'] == 200){
					if($settings['poster_type'] == 1 && $type == 1){
						$mtwm_url = $wm['data']['we_app_info']['page_path'];
						$mtwm_h5 = $settings['waimaitt_meituanwm_tuantext_c'].$wm['data']['h5'];
						$mtwm_qrcode = str_replace(array("http","https"),"https",$wm['data']['we_app_info']['miniCode']);
					}else{
						$mtwm_url = $wm['data']['we_app_info']['page_path'];
						$mtwm_h5 = $settings['waimaitt_meituanwm_tuantext_c'].$wm['data']['h5'];
						$mtwm_qrcode = str_replace(array("http","https"),"https",$wm['data']['we_app_info']['miniCode']);
					}
				}else{
					$mtwm_url = '';$mtwm_h5 = '';$mtwm_qrcode = '';
				}
				$backdata = array('mtwm_url' =>$mtwm_url,'mtwm_h5' => $mtwm_h5,'mtwm_qrcode' => $mtwm_qrcode);
			}elseif($appid_type == 2){
				//闪购
				$wm = file_get_contents("http://api.tbk.dingdanxia.com/waimai/meituan_sg_privilege", false, $cxContext);
				if($settings['errorcodeid'] == 63){
						var_dump($wm);
					}
				$wm = json_decode($wm,true);
				if($wm['code'] == 200){
					if($settings['poster_type'] == 1 && $type == 1){
						$mtsc_url = $wm['data']['we_app_info']['page_path'];
						$mtsc_h5 = $settings['waimaitt_meituansc_tuantext_c'].$wm['data']['h5'];
						$mtsc_qrcode = str_replace(array("http","https"),"https",$wm['data']['we_app_info']['miniCode']);
					}else{
						$mtsc_url = $wm['data']['we_app_info']['page_path'];
						$mtsc_h5 = $settings['waimaitt_meituansc_tuantext_c'].$wm['data']['h5'];
						$mtsc_qrcode = str_replace(array("http","https"),"https",$wm['data']['we_app_info']['miniCode']);
					}
				}else{
					$mtsc_url = '';$mtsc_h5 = '';$mtsc_qrcode = '';
				}
				$backdata = array('mtsc_url' => $mtsc_url,'mtsc_qrcode' =>$mtsc_qrcode,'mtsc_h5' =>$mtsc_h5);
			}
		}
		
		//获取美团推广链接
		$ret = json_encode($backdata);
		$data = array();
		$data["key"] = substr(md5(time() . uniqid()), 0, 16);
		$data["data"] = $this->aesEn($ret, $data["key"]);
		exit(json_encode(array('code' => 0, 'status' => 1, 'msg' => 'SUCCESS', 'data' => $data, 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
	}elseif($appid_type == 3 || $appid_type == 4){
		//查询是否有pid空闲
		$user = pdo_get($this->modulename . "_user_u", array("unionid" => $unionid, "system_id" => $settings['system_id']));
		if($user['relation_id']){//如果用户已经绑定渠道id，则使用渠道id
			$relation_id = $user['relation_id'];
			$pid = explode("_",$settings['tbqudaopid']);
			if($appid_type == 3){
				if($elmwm_act_id){
					$settings['elmwm_promotion_scene_id'] = $elmwm_act_id;
				}else{
					if(!$settings['elmwm_promotion_scene_id']){
						$settings['elmwm_promotion_scene_id'] = '1571715733668';
					}
				}
				$elmwm_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?adzone_id='.$pid[3].'&site_id='.$pid[2].'&promotion_scene_id='.$settings['elmwm_promotion_scene_id'].'&relation_id='.$relation_id.'&appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&platform=2'),true);
				if($settings['errorcodeid'] == 64){
					var_dump($elmwm_url);
				}
				if($elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url']){
					if($settings['poster_type'] == 1){
						$backdata = array('elmwm_url' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmwm_qrcode' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmwm_h5' =>$settings['waimaitt_elmwm_tuantext_c']."：".$elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
					}else{
						$backdata = array('elmwm_url' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmwm_qrcode' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmwm_h5' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
					}
					
				}else{
					$backdata = array('elmwm_url' =>'','elmwm_qrcode' =>'','elmwm_h5' =>'','is_qudao' =>1,'pid_time' =>$pid_use_time);
				}
			}elseif($appid_type == 4){
				if(!$settings['elmsc_promotion_scene_id']){$settings['elmsc_promotion_scene_id'] = '1585018034441';}
				$elmsc_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?adzone_id='.$pid[3].'&site_id='.$pid[2].'&promotion_scene_id='.$settings['elmsc_promotion_scene_id'].'&relation_id='.$relation_id.'&appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&platform=2'),true);
				if($settings['errorcodeid'] == 65){
					var_dump($elmsc_url);
				}
				if($elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url']){
					if($settings['poster_type'] == 1){
						$backdata = array('elmsc_url' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmsc_qrcode' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmsc_h5' =>$settings['waimaitt_elmsc_tuantext_c']."：".$elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
					}else{
						$backdata = array('elmsc_url' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmsc_qrcode' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmsc_h5' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
					}
					
				}else{
					$backdata = array('elmsc_url' =>'','elmsc_qrcode' =>'','elmsc_h5' =>'','is_qudao' =>1,'pid_time' =>$pid_use_time);
				}
			}
			$ret = json_encode($backdata);
			$data = array();
			$data["key"] = substr(md5(time() . uniqid()), 0, 16);
			$data["data"] = $this->aesEn($ret, $data["key"]);
			exit(json_encode(array('code' => 0, 'status' => 2, 'msg' => 'SUCCESS', 'data' => $data, 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
		}else{//如果没有绑定渠道id，则使用pid
			$pid = pdo_get($this->modulename . "_pid_u", array("unionid" => $unionid,"is_use" => 1, "system_id" => $settings['system_id']));
			if($pid){$pid_use_time = $pid['use_time'];}
			if(!$pid){
				$pid = pdo_get($this->modulename . "_pid_u", array("is_use" => 0, "system_id" => $settings['system_id']));
				$pid_use_time = time();
			}
			//有pid空闲
			if($pid){
				pdo_update($this->modulename . "_pid_u", array("nickname" => $user['nickname'],"openid" => $openid,"unionid" => $user['unionid'],"uid" => $user['user_id'],"is_use" => 1,"use_time" => $pid_use_time,"update_time" => time()), array("id" => $pid['id']));
				$pid_array = explode("_",$pid['pid']);
				if($appid_type == 3){
					if($elmwm_act_id){
						$settings['elmwm_promotion_scene_id'] = $elmwm_act_id;
					}else{
						if(!$settings['elmwm_promotion_scene_id']){
							$settings['elmwm_promotion_scene_id'] = '1571715733668';
						}
					}
					if($pid['rid']){
						$elmwm_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?adzone_id='.$pid_array[3].'&site_id='.$pid_array[2].'&promotion_scene_id='.$settings['elmwm_promotion_scene_id'].'&relation_id='.$pid['rid'].'&appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&platform=2'),true);
						if($settings['errorcodeid'] == 66){
							var_dump($elmwm_url);
						}
					}else{
						$elmwm_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?appkey='.$settings['appkey'].'&sid='.$pid['sid'].'&adzone_id='.$pid_array[3].'&site_id='.$pid_array[2].'&promotion_scene_id='.$settings['elmwm_promotion_scene_id'].'&platform=2'),true);
						if($settings['errorcodeid'] == 67){
							var_dump($elmwm_url);
						}
					}
					if($elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url']){
						if($settings['poster_type'] == 1){
							$backdata = array('elmwm_url' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmwm_qrcode' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmwm_h5' =>$settings['waimaitt_elmwm_tuantext_c']."：".$elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
						}else{
							$backdata = array('elmwm_url' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmwm_qrcode' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmwm_h5' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
						}
						
					}else{
						$backdata = array('elmwm_url' =>'','elmwm_qrcode' =>'','elmwm_h5' =>'','is_qudao' =>0,'pid_time' =>$pid_use_time);
					}
				}elseif($appid_type == 4){
					if(!$settings['elmsc_promotion_scene_id']){$settings['elmsc_promotion_scene_id'] = '1585018034441';}
					if($pid['rid']){
						$elmsc_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?adzone_id='.$pid_array[3].'&site_id='.$pid_array[2].'&promotion_scene_id='.$settings['elmsc_promotion_scene_id'].'&relation_id='.$pid['rid'].'&appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&platform=2'),true);
						if($settings['errorcodeid'] == 68){
							var_dump($elmsc_url);
						}
					}else{
						$elmsc_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?appkey='.$settings['appkey'].'&sid='.$pid['sid'].'&adzone_id='.$pid_array[3].'&site_id='.$pid_array[2].'&promotion_scene_id='.$settings['elmsc_promotion_scene_id'].'&platform=2'),true);
						if($settings['errorcodeid'] == 69){
							var_dump($elmsc_url);
						}
					}
					if($elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url']){
						if($settings['poster_type'] == 1){
							$backdata = array('elmsc_url' => $elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmsc_qrcode' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmsc_h5' =>$settings['waimaitt_elmsc_tuantext_c']."：".$elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>0,'pid_time' =>$pid_use_time);
						}else{
							$backdata = array('elmsc_url' => $elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmsc_qrcode' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmsc_h5' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>0,'pid_time' =>$pid_use_time);
						}
						
					}else{
						$backdata = array('elmsc_url' => '','elmsc_qrcode' =>'','elmsc_h5' =>'','is_qudao' =>0,'pid_time' =>$pid_use_time);
					}
				}
				$ret = json_encode($backdata);
				$data = array();
				$data["key"] = substr(md5(time() . uniqid()), 0, 16);
				$data["data"] = $this->aesEn($ret, $data["key"]);
				exit(json_encode(array('code' => 0, 'status' => 2, 'msg' => 'SUCCESS', 'data' => $data, 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
			}else{//没有pid空闲，则使用渠道
				$inviter_code = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_sc_invitecode_get.ashx?appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&relation_app=common&code_type=1'),true);
				if($settings['errorcodeid'] == 70){
					var_dump($inviter_code);
				}
				$inviter_code = $inviter_code['tbk_sc_invitecode_get_response']['data']['inviter_code'];
				$qudao_url = 'https://mos.m.taobao.com/inviter/register?inviterCode='.$inviter_code.'&src=pub&app=common&rtag='.$user['uid'].'A'.time();
				$tkl = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_tkl_create.ashx?appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&url='.urlencode($qudao_url)),true);
				if($settings['errorcodeid'] == 71){
					var_dump($tkl);
				}
				if($tkl['status'] == 200){
					$qudaotkl = $tkl['model'];
					exit(json_encode(array('code' => 0, 'status' => 1, 'msg' => 'SUCCESS', 'data' => '3&#55357;&#56392;'.$qudaotkl.'打开&#55357;&#56393;淘bao&#55357;&#56392;或点击链接 https://m.tb.cn/h.aaaaaaa 至浏览器[渠道方备案完成后，可为您进行商品/店铺和更多物料的推广]', 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
				}else{
					exit(json_encode(array('code' => 0, 'status' => 0, 'msg' => '获取渠道信息错误', 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
				}
			}
		}
	}
}else{
	if($appid_type == 1 || $appid_type == 2){
		$user = pdo_get($this->modulename . "_user", array("openid" => $openid, "uniacid" => $_W["uniacid"]));
		//获取美团推广链接
		if($settings['meituan_api_type'] == 1){
			if($appid_type == 1){
				if(!intval($settings["meituan_waimai_h5_url"])){$settings['meituan_waimai_h5_url'] = 2;}
				if($settings['poster_type'] == 1 && $type == 1){
					$params = array('actId' => $settings['meituan_waimai_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'linkType' => 1,'sign' => 1);
					$meituansign = $this->genSign($params,$settings['meituanapikey']);
					$res = file_get_contents('https://runion.meituan.com/generateLink?actId='.$settings['meituan_waimai_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&linkType=1&sign='.$meituansign);
					if($settings['errorcodeid'] == 56){
						var_dump($res);
					}
				}else{
					$params = array('actId' => $settings['meituan_waimai_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'linkType' => 4,'sign' => 1);
					$meituansign = $this->genSign($params,$settings['meituanapikey']);
					$res = file_get_contents('https://runion.meituan.com/generateLink?actId='.$settings['meituan_waimai_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&linkType=4&sign='.$meituansign);
					if($settings['errorcodeid'] == 57){
						var_dump($res);
					}
				}
				$res = json_decode($res,true);
				if($res['status'] == 0){
					if($settings['poster_type'] == 1 && $type == 1){
						$params = array('actId' => $settings['meituan_waimai_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'sign' => 1);
						$meituansign = $this->genSign($params,$settings['meituanapikey']);
						$rescode = file_get_contents('https://runion.meituan.com/miniCode?actId='.$settings['meituan_waimai_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&sign='.$meituansign);
						if($settings['errorcodeid'] == 58){
							var_dump($rescode);
						}
						$rescode = json_decode($rescode,true);
						$mtwm_url = $res['data'];
						$mtwm_h5 = $settings['waimaitt_meituanwm_tuantext_c'].$res['data'];
						$mtwm_qrcode = str_replace(array("http","https"),"https",$rescode['data']);
					}else{
						$mtwm_url = $res['data'];$mtwm_h5 = '';$mtwm_qrcode = '';
					}
				}
				$backdata = array('mtwm_url' =>$mtwm_url,'mtwm_h5' => $mtwm_h5,'mtwm_qrcode' => $mtwm_qrcode);
			}elseif($appid_type == 2){
				if(!intval($settings["meituan_sc_h5_url"])){$settings['meituan_sc_h5_url'] = 4;}
				if($settings['poster_type'] == 1 && $type == 1){
					$params = array('actId' => $settings['meituan_sc_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'linkType' => 1,'sign' => 1);
					$meituansign = $this->genSign($params,$settings['meituanapikey']);
					$res = file_get_contents('https://runion.meituan.com/generateLink?actId='.$settings['meituan_sc_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&linkType=1&sign='.$meituansign);
					if($settings['errorcodeid'] == 59){
						var_dump($res);
					}
				}else{
					$params = array('actId' => $settings['meituan_sc_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'linkType' => 4,'sign' => 1);
					$meituansign = $this->genSign($params,$settings['meituanapikey']);
					$res = file_get_contents('https://runion.meituan.com/generateLink?actId='.$settings['meituan_sc_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&linkType=4&sign='.$meituansign);
					if($settings['errorcodeid'] == 60){
						var_dump($res);
					}
				}
				$res = json_decode($res,true);
				if($res['status'] == 0){
					if($settings['poster_type'] == 1 && $type == 1){
						$params = array('actId' => $settings['meituan_sc_h5_url'],'key' => $settings['meituanappkey'],'sid' => $user['uid'],'sign' => 1);
						$meituansign = $this->genSign($params,$settings['meituanapikey']);
						$rescode = file_get_contents('https://runion.meituan.com/miniCode?actId='.$settings['meituan_sc_h5_url'].'&key='.$settings['meituanappkey'].'&sid='.$user['uid'].'&sign='.$meituansign);
						if($settings['errorcodeid'] == 61){
							var_dump($rescode);
						}
						$rescode = json_decode($rescode,true);
						$mtsc_url = $res['data'];
						$mtsc_h5 = $settings['waimaitt_meituansc_tuantext_c'].$res['data'];
						$mtsc_qrcode = str_replace(array("http","https"),"https",$rescode['data']);
					}else{
						$mtsc_url = $res['data'];$mtsc_h5 = '';$mtsc_qrcode = '';
					}
				}
				$backdata = array('mtsc_url' => $mtsc_url,'mtsc_h5' => $mtsc_h5,'mtsc_qrcode' => $mtsc_qrcode);
			}
		}elseif($settings['meituan_api_type'] == 2){
			if($appid_type == 1){
				$meituan_data["activity"] = $settings['meituangroup_waimai_activity'];
			}elseif($appid_type == 2){
				$meituan_data["activity"] = $settings['meituangroup_sc_activity'];
			}
			$timestamp = time();
			$key = $settings['meituangroup_AppKey'];
			$meituan_data["utmSource"] = $settings['meituangroup_utmSource'];
			$meituan_data["utmMedium"] = $this->aesencrypt($user['uid'],$key);
			pdo_update($this->modulename . "_user", array("utmMedium" => $meituan_data["utmMedium"]), array("openid" => $openid, "uniacid" => $_W["uniacid"]));
			if($settings['system_type'] == 1){
				pdo_update($this->modulename . "_user_u", array("utmMedium" => $meituan_data["utmMedium"]), array("unionid" => $unionid, "system_id" => $settings['system_id']));
			}
			$meituan_data["promotionId"] = $settings['meituangroup_pid'];
			$meituan_data["pageLevel"] = 1;
			$requestId = $meituan_data["utmSource"] . $timestamp;
			$accessToken = $this->aesencrypt($requestId,$key);
			$url = "https://union.dianping.com/api/promotion/link?timestamp=" . $timestamp . "&requestId=" . $requestId . "&utmSource=" . $meituan_data["utmSource"] . "&version=2.0&accessToken=" . $accessToken;
			$res = $this->curlPost($url,$meituan_data);
			if($appid_type == 1){
				$backdata = array('mtwm_url' => $res['data']['miniProgramPath'],'mtwm_h5' => $res['data']['shortLink'],'mtwm_qrcode' => $res['data']['miniProgramQrCode'],'mtwm_apitype' => 2);
			}elseif($appid_type == 2){
				$backdata = array('mtsc_url' => $res['data']['miniProgramPath'],'mtsc_h5' => $res['data']['shortLink'],'mtsc_qrcode' => $res['data']['miniProgramQrCode'],'mtwm_apitype' => 2);
			}
		}elseif($settings['meituan_api_type'] == 4){
			if($appid_type == 1){
				$actid = 1;
			}elseif($appid_type == 2){
				$actid = 2;
			}
			
			$res = json_decode(file_get_contents('http://api.jutuike.com/union/act?relation_flag_name=waimaixia&apikey='.$settings['jutuikeapikey'].'&act_id='.$actid.'&sid='.$user['uid']),true);
			if ($res['code'] == 1) {
				if($appid_type == 1){
					$backdata = array('mtwm_url' => $res['data']['we_app_info']['page_path'],'mtwm_h5' => $res['data']['h5'],'mtwm_qrcode' => $res['data']['we_app_info']['miniCode'],'mtwm_apitype' => 4);
				}elseif($appid_type == 2){
					$backdata = array('mtsc_url' => $res['data']['we_app_info']['page_path'],'mtsc_h5' => $res['data']['h5'],'mtsc_qrcode' => $res['data']['we_app_info']['miniCode'],'mtwm_apitype' => 4);
				}
				
			} else {
				exit(json_encode($res));
			}
		}else{
			$postdata = http_build_query(array('apikey' => $settings['ddxapikey'],'sid' => $user['uid'],'generate_we_app' => true,'qrcode' => true));
			$options = array(
					'http' => array(
					'method' => 'POST',
					'header' => 'Content-type:application/x-www-form-urlencoded',
					'content' => $postdata,
					'timeout' => 1 * 60 // 超时时间（单位:s）
				  )
				);
			$cxContext = stream_context_create($options);
			if($appid_type == 1){
				//外卖
				$wm = file_get_contents("http://api.tbk.dingdanxia.com/waimai/meituan_privilege", false, $cxContext);
				if($settings['errorcodeid'] == 62){
					var_dump($wm);
				}
				$wm = json_decode($wm,true);
				if($wm['code'] == 200){
					if($settings['poster_type'] == 1 && $type == 1){
						$mtwm_url = $wm['data']['we_app_info']['page_path'];
						$mtwm_h5 = $settings['waimaitt_meituanwm_tuantext_c'].$wm['data']['h5'];
						$mtwm_qrcode = str_replace(array("http","https"),"https",$wm['data']['we_app_info']['miniCode']);
					}else{
						$mtwm_url = $wm['data']['we_app_info']['page_path'];$mtwm_h5 = '';$mtwm_qrcode = '';
					}
				}else{
					$mtwm_url = '';$mtwm_h5 = '';$mtwm_qrcode = '';
				}
				$backdata = array('mtwm_url' =>$mtwm_url,'mtwm_h5' => $mtwm_h5,'mtwm_qrcode' => $mtwm_qrcode);
			}elseif($appid_type == 2){
				//闪购
				$wm = file_get_contents("http://api.tbk.dingdanxia.com/waimai/meituan_sg_privilege", false, $cxContext);
				if($settings['errorcodeid'] == 63){
						var_dump($wm);
					}
				$wm = json_decode($wm,true);
				if($wm['code'] == 200){
					if($settings['poster_type'] == 1 && $type == 1){
						
						$mtsc_url = $wm['data']['we_app_info']['page_path'];
						$mtsc_h5 = $settings['waimaitt_meituansc_tuantext_c'].$wm['data']['h5'];
						$mtsc_qrcode = str_replace(array("http","https"),"https",$wm['data']['we_app_info']['miniCode']);
					}else{
						$mtsc_url = $wm['data']['we_app_info']['page_path'];$mtsc_h5 = '';$mtsc_qrcode = '';
					}
				}else{
					$mtsc_url = '';$mtsc_h5 = '';$mtsc_qrcode = '';
				}
				$backdata = array('mtsc_url' => $mtsc_url,'mtsc_qrcode' =>$mtsc_qrcode,'mtsc_h5' =>$mtsc_h5);
			}
		}
		
		//获取美团推广链接
		$ret = json_encode($backdata);
		$data = array();
		$data["key"] = substr(md5(time() . uniqid()), 0, 16);
		$data["data"] = $this->aesEn($ret, $data["key"]);
		exit(json_encode(array('code' => 0, 'status' => 1, 'msg' => 'SUCCESS', 'data' => $data, 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
	}elseif($appid_type == 3 || $appid_type == 4){
		//查询是否有pid空闲
		$user = pdo_get($this->modulename . "_user", array("openid" => $openid, "uniacid" => $_W["uniacid"]));
		if($user['relation_id']){//如果用户已经绑定渠道id，则使用渠道id
			$relation_id = $user['relation_id'];
			$pid = explode("_",$settings['tbqudaopid']);
			if($appid_type == 3){
				if($elmwm_act_id){
					$settings['elmwm_promotion_scene_id'] = $elmwm_act_id;
				}else{
					if(!$settings['elmwm_promotion_scene_id']){
						$settings['elmwm_promotion_scene_id'] = '1571715733668';
					}
				}
				$elmwm_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?adzone_id='.$pid[3].'&site_id='.$pid[2].'&promotion_scene_id='.$settings['elmwm_promotion_scene_id'].'&relation_id='.$relation_id.'&appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&platform=2'),true);
				if($settings['errorcodeid'] == 76){
					var_dump($elmwm_url);
				}
				if($elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url']){
					if($settings['poster_type'] == 1){
						$backdata = array('elmwm_url' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmwm_qrcode' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmwm_h5' =>$settings['waimaitt_elmwm_tuantext_c']."：".$elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
					}else{
						$backdata = array('elmwm_url' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmwm_qrcode' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmwm_h5' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
					}
					
				}else{
					$backdata = array('elmwm_url' =>'','elmwm_qrcode' =>'','elmwm_h5' =>'','is_qudao' =>1,'pid_time' =>$pid_use_time);
				}
			}elseif($appid_type == 4){
				if(!$settings['elmsc_promotion_scene_id']){$settings['elmsc_promotion_scene_id'] = '1585018034441';}
				$elmsc_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?adzone_id='.$pid[3].'&site_id='.$pid[2].'&promotion_scene_id='.$settings['elmsc_promotion_scene_id'].'&relation_id='.$relation_id.'&appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&platform=2'),true);
				if($settings['errorcodeid'] == 77){
					var_dump($elmsc_url);
				}
				if($elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url']){
					if($settings['poster_type'] == 1){
						$backdata = array('elmsc_url' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmsc_qrcode' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmsc_h5' =>$settings['waimaitt_elmsc_tuantext_c']."：".$elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
					}else{
						$backdata = array('elmsc_url' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmsc_qrcode' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmsc_h5' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
					}
					
				}else{
					$backdata = array('elmsc_url' =>'','elmsc_qrcode' =>'','elmsc_h5' =>'','is_qudao' =>1,'pid_time' =>$pid_use_time);
				}
			}
			$ret = json_encode($backdata);
			$data = array();
			$data["key"] = substr(md5(time() . uniqid()), 0, 16);
			$data["data"] = $this->aesEn($ret, $data["key"]);
			exit(json_encode(array('code' => 0, 'status' => 2, 'msg' => 'SUCCESS', 'data' => $data, 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
		}else{//如果没有绑定渠道id，则使用pid
			$pid = pdo_get($this->modulename . "_pid", array("openid" => $openid,"is_use" => 1, "uniacid" => $_W["uniacid"]));
			if($pid){$pid_use_time = $pid['use_time'];}
			if(!$pid){
				$pid = pdo_get($this->modulename . "_pid", array("is_use" => 0, "uniacid" => $_W["uniacid"]));
				$pid_use_time = time();
			}
			//有pid空闲
			if($pid){
				pdo_update($this->modulename . "_pid", array("nickname" => $user['nickname'],"openid" => $openid,"unionid" => $user['unionid'],"uid" => $user['user_id'],"is_use" => 1,"use_time" => $pid_use_time,"update_time" => time()), array("id" => $pid['id']));
				$pid_array = explode("_",$pid['pid']);
				if($appid_type == 3){
					if($elmwm_act_id){
						$settings['elmwm_promotion_scene_id'] = $elmwm_act_id;
					}else{
						if(!$settings['elmwm_promotion_scene_id']){
							$settings['elmwm_promotion_scene_id'] = '1571715733668';
						}
					}
					if($pid['rid']){
						$elmwm_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?adzone_id='.$pid_array[3].'&site_id='.$pid_array[2].'&promotion_scene_id='.$settings['elmwm_promotion_scene_id'].'&relation_id='.$pid['rid'].'&appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&platform=2'),true);
						if($settings['errorcodeid'] == 78){
							var_dump($elmwm_url);
						}
					}else{
						$elmwm_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?appkey='.$settings['appkey'].'&sid='.$pid['sid'].'&adzone_id='.$pid_array[3].'&site_id='.$pid_array[2].'&promotion_scene_id='.$settings['elmwm_promotion_scene_id'].'&platform=2'),true);
						if($settings['errorcodeid'] == 79){
							var_dump($elmwm_url);
						}
					}
					if($elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url']){
						if($settings['poster_type'] == 1){
							$backdata = array('elmwm_url' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmwm_qrcode' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmwm_h5' =>$settings['waimaitt_elmwm_tuantext_c']."：".$elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
						}else{
							$backdata = array('elmwm_url' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmwm_qrcode' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmwm_h5' =>$elmwm_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>1,'pid_time' =>$pid_use_time );
						}
						
					}else{
						$backdata = array('elmwm_url' =>'','elmwm_qrcode' =>'','elmwm_h5' =>'','is_qudao' =>0,'pid_time' =>$pid_use_time);
					}
				}elseif($appid_type == 4){
					if(!$settings['elmsc_promotion_scene_id']){$settings['elmsc_promotion_scene_id'] = '1585018034441';}
					if($pid['rid']){
						$elmsc_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?adzone_id='.$pid_array[3].'&site_id='.$pid_array[2].'&promotion_scene_id='.$settings['elmsc_promotion_scene_id'].'&relation_id='.$pid['rid'].'&appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&platform=2'),true);
						if($settings['errorcodeid'] == 80){
							var_dump($elmsc_url);
						}
					}else{
						$elmsc_url = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_activitylink_get.ashx?appkey='.$settings['appkey'].'&sid='.$pid['sid'].'&adzone_id='.$pid_array[3].'&site_id='.$pid_array[2].'&promotion_scene_id='.$settings['elmsc_promotion_scene_id'].'&platform=2'),true);
						if($settings['errorcodeid'] == 81){
							var_dump($elmsc_url);
						}
					}
					if($elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url']){
						if($settings['poster_type'] == 1){
							$backdata = array('elmsc_url' => $elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmsc_qrcode' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmsc_h5' =>$settings['waimaitt_elmsc_tuantext_c']."：".$elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>0,'pid_time' =>$pid_use_time);
						}else{
							$backdata = array('elmsc_url' => $elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_miniprogram_path'],'elmsc_qrcode' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['wx_qrcode_url'],'elmsc_h5' =>$elmsc_url['tbk_sc_activity_info_get_response']['data']['short_click_url'],'is_qudao' =>0,'pid_time' =>$pid_use_time);
						}
						
					}else{
						$backdata = array('elmsc_url' => '','elmsc_qrcode' =>'','elmsc_h5' =>'','is_qudao' =>0,'pid_time' =>$pid_use_time);
					}
				}
				$ret = json_encode($backdata);
				$data = array();
				$data["key"] = substr(md5(time() . uniqid()), 0, 16);
				$data["data"] = $this->aesEn($ret, $data["key"]);
				exit(json_encode(array('code' => 0, 'status' => 2, 'msg' => 'SUCCESS', 'data' => $data, 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
			}else{//没有pid空闲，则使用渠道
				$inviter_code = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_sc_invitecode_get.ashx?appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&relation_app=common&code_type=1'),true);
				$inviter_code = $inviter_code['tbk_sc_invitecode_get_response']['data']['inviter_code'];
				$qudao_url = 'https://mos.m.taobao.com/inviter/register?inviterCode='.$inviter_code.'&src=pub&app=common&rtag='.$user['uid'].'A'.time();
				$tkl = json_decode(file_get_contents('https://api.zhetaoke.com:10001/api/open_tkl_create.ashx?appkey='.$settings['appkey'].'&sid='.$settings['sid'].'&url='.urlencode($qudao_url)),true);
				if($settings['errorcodeid'] == 82){
					var_dump($tkl);
				}
				if($tkl['status'] == 200){
					$qudaotkl = $tkl['model'];
					exit(json_encode(array('code' => 0, 'status' => 1, 'msg' => 'SUCCESS', 'data' => '3&#55357;&#56392;'.$qudaotkl.'打开&#55357;&#56393;淘bao&#55357;&#56392;或点击链接 https://m.tb.cn/h.aaaaaaa 至浏览器[渠道方备案完成后，可为您进行商品/店铺和更多物料的推广]', 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
				}else{
					exit(json_encode(array('code' => 0, 'status' => 0, 'msg' => '获取渠道信息错误', 'sharetitle' => $share['title'], 'sharepic' => tomedia($share['thumb']))));
				}
			}
		}
	}
}